import { getBannerListReq } from "@/service/banner"
import { IBanner } from '../banner'
import { Effect, ImmerReducer } from 'umi'
export interface IBannerState {
  bannerList: Array<IBanner>
}
export interface IBannerModel {
  namespace: 'banner',
  state: IBannerState,
  effects: {
    getBannerListEffect: Effect
  },
  reducers: {
    UPDATE_BANNER_LIST: ImmerReducer
  }
}
// pages下子目录中创建models文件夹
const bannerModel: IBannerModel = {
  namespace: 'banner',
  state: {
    bannerList: []
  },
  effects: {
    * getBannerListEffect ({payload}, {call, put}) {
      const res = yield call(getBannerListReq, payload)
      yield put({
        type: 'UPDATE_BANNER_LIST',
        payload: res.data
      })
    }
  },
  reducers: {
    UPDATE_BANNER_LIST(state, action) {
      state.bannerList = action.payload
    }
  }
}
export default bannerModel
